import sysapi from "@/api/declaration/sysApi"
import httpRequest from "@/config/axios/httpRequest"
import { 
  CreateSignatureFileReq, 
  PreviewSignatureFileReq, 
  PreviewSignatureFileResp, 
  QuerySignatureFileReq, 
  UpdateSignatureFileReq 
} from "@/models/system/SignatureFileModel"

export interface FilePageReqVO extends PageParam {
  path?: string
  type?: string
  createTime?: Date[]
}

// 文件预签名地址 Response VO
export interface FilePresignedUrlRespVO {
  // 文件配置编号
  configId: number
  // 文件上传 URL
  uploadUrl: string
  // 文件 URL
  url: string
}

// 查询文件列表
export const getFilePage = async (params: QuerySignatureFileReq) => {
  return await httpRequest.get(sysapi.QuerySignatureFile, { params })
}

// 删除文件
export const deleteFile = async (id: number) => {
  return await httpRequest.delete(sysapi.DeleteSignatureFile, { params: { ID:id } })
}

// 获取文件预签名地址
export const getFilePresignedUrl = async (path: PreviewSignatureFileReq) => {
  return await httpRequest.get<PreviewSignatureFileResp>(sysapi.PreviewSignatureFile,{ params: path })
}

// 创建文件
export const createFile = async (data: CreateSignatureFileReq) => {
  return await httpRequest.post(sysapi.CreateSignatureFile, data)
}

// 上传文件
export const updateFile = async (data: UpdateSignatureFileReq) => {
  return await httpRequest.upload(sysapi.UploadSignatureFile, data,{ headers: {
    "Content-Type": "multipart/form-data"
  } })
}
